package cn.kxx.interceptor;

import cn.kxx.entity.Result;
import cn.kxx.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**

 全局异常处理器
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    /**

     处理自定义异常
     */
    @ExceptionHandler(value = BusinessException.class)
    @ResponseBody
    public Result processBusinessExcetion(BusinessException e){
        String message = e.getMessage();
        return new Result(false,message);
    }

    /**

     处理系统异常
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result processExcetion(Exception e){
        log.info("=================>>>>>发生系统异常:"+e.getMessage());
        return new Result(false,"未知异常");
    }
}